package cn.tedu.straw.commons.vo;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author shkstart
 * @create 2020-07-15 17:41
 */
@Data
@Accessors(chain = true)
public class R<T> {//表示Result

    private Integer state;
    private String message;
    private T data;

    public static R ok() {
        return new R().setState(State.OK);
    }
    public static <T> R ok(T data){
        return new R<T>().setState(State.OK).setData(data);
    }

    public static R failure(Integer state, String message) {
        return new R().setState(state).setMessage(message);
    }

    public static R failure(Integer state, Throwable e) {
        return failure(state, e.getMessage());
    }

    public static interface State {
        int OK = 2000;
        int ERR_PARAMETER_INVALIDATION=4000;
        int ERR_INVITE_COOE = 4001;
        int ERR_CLASS_DISABLED = 4002;
        int ERR_PHONE_DUPLITCATE = 4003;
        int ERR_INSERT = 4004;
        int ERR_ACCESS_DENIDE=5000;
        int ERR_FILE_EMPTY=4004;
        int ERR_FILE_SIZE=4005;
        int ERR_FILE_TYPE=4006;
        int ERR_FILE_IOE=4007;
        int ERR_QUESTION_NOTFOUND=4008;
        int ERR_COMMENT_NOT_FOUND=4009;
        int ERR_PERMISSION_DENIED=4040;
        int ERR_DELETE=4011;
        int ERR_SELECT=4012;
        int ERR_ANSWER_NOT_FOUND=4013;
        int ERR_UNKNOWN = 9999;
    }
}
